package cn.lx.elasticsearch.autocomplete.entity;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;
import org.springframework.data.elasticsearch.annotations.CompletionField;
import org.springframework.data.elasticsearch.annotations.DateFormat;
import org.springframework.data.elasticsearch.core.completion.Completion;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 用户实体类 - 用于演示用户搜索自动补全
 * 
 * @author lx
 * @since 2024-01-01
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@Document(indexName = "users")
public class User {

    @Id
    private String id;

    /**
     * 用户名 - 用于自动补全
     */
    @Field(type = FieldType.Text, analyzer = "ik_max_word")
    private String username;

    /**
     * 真实姓名
     */
    @Field(type = FieldType.Text, analyzer = "ik_max_word")
    private String realName;

    /**
     * 自动补全字段 - 真正的 completion 字段
     */
    @CompletionField(maxInputLength = 50)
    private Completion usernameSuggest;

    /**
     * 邮箱
     */
    @Field(type = FieldType.Keyword)
    private String email;

    /**
     * 手机号
     */
    @Field(type = FieldType.Keyword)
    private String phone;

    /**
     * 年龄
     */
    @Field(type = FieldType.Integer)
    private Integer age;

    /**
     * 性别：1-男，2-女
     */
    @Field(type = FieldType.Integer)
    private Integer gender;

    /**
     * 城市
     */
    @Field(type = FieldType.Keyword)
    private String city;

    /**
     * 职业
     */
    @Field(type = FieldType.Keyword)
    private String profession;

    /**
     * 兴趣爱好
     */
    @Field(type = FieldType.Keyword)
    private List<String> hobbies;

    /**
     * 用户状态：1-正常，0-禁用
     */
    @Field(type = FieldType.Integer)
    private Integer status;

    /**
     * 注册时间
     */
    @Field(type = FieldType.Date, format = DateFormat.date)
    private LocalDateTime registerTime;

    /**
     * 最后登录时间
     */
    @Field(type = FieldType.Date, format = DateFormat.date)
    private LocalDateTime lastLoginTime;

    /**
     * 用户等级
     */
    @Field(type = FieldType.Integer)
    private Integer level;

    /**
     * 积分
     */
    @Field(type = FieldType.Long)
    private Long points;
}
